<template>
  <div class="sex-box">
    <div class="sex-top">
      <p class="title">男女比列</p>
      <p class="bg"></p>
    </div>
    <div class="sex-number">
      <div class="sex-man">
        <span>男士</span>
        <img src="../../images/man.png" alt="" style="margin-top: 10px" />
      </div>
      <div class="sex-woman">
        <span>女士</span>
        <img src="../../images/woman.png" alt="" style="margin-top: 10px" />
      </div>
    </div>
    <div class="sex-rate">
      <p style="margin-right: 50px">58%</p>
      <p style="margin-left: 50px">42%</p>
    </div>
    <div class="sex-charts" ref="male"></div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
// 引入echarts
import 'echarts-liquidfill'
import * as echarts from 'echarts'
// 设置组件名
defineOptions({
  name: 'Sex',
})
// 生命周期钩子
onMounted(() => {
  // 初始化echarts实例
  let mycharts = echarts.init(male.value)
  // 配置 - 配置项
  let option = {
    //组件标题
    title: {
      text: '男女比例', //主标题
      textStyle: {
        //主标题颜色
        color: 'skyblue',
      },
      left: '40%',
    },
    //x|y
    xAxis: {
      show: false,
      min: 0,
      max: 100,
    },
    yAxis: {
      show: false,
      type: 'category',
    },
    series: [
      {
        type: 'bar',
        data: [58],
        barWidth: 20,
        z: 100,
        itemStyle: {
          color: 'skyblue',
          borderRadius: 20,
        },
      },
      {
        type: 'bar',
        data: [100],
        barWidth: 20,
        //调整女士柱条位置
        barGap: '-100%',
        itemStyle: {
          color: 'pink',
          borderRadius: 20,
        },
      },
    ],
    grid: {
      left: '10%',
      top: 0,
      right: '10%',
      bottom: 0,
    },
  }
  // 设置 - 配置项
  mycharts.setOption(option)
})
// 获取dom实例
let male = ref()
</script>

<style scoped lang="scss">
.sex-box {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin: 20px 0px;

  .sex-top {
    .title {
      color: #59b4e6;
      font-size: 20px;
    }

    .bg {
      width: 68px;
      height: 7px;
      background: url(../../images/dataScreen-title.png);
      margin-top: 20px;
    }
  }

  .sex-number {
    display: flex;
    justify-content: center;

    .sex-man {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 111px;
      height: 115px;
      background: url(../../images/man-bg.png) no-repeat;
      margin-top: 20px;
      margin-right: 10px;
    }

    .sex-woman {
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 111px;
      height: 115px;
      background: url(../../images/woman-bg.png) no-repeat;
      margin-top: 20px;
      margin-left: 10px;
    }
  }

  .sex-rate {
    display: flex;
    justify-content: center;
    color: #59b4e6;
  }

  .sex-charts {
    height: 100px;
  }
}
</style>
